<template>
	<view class="sheets">
		<div class="sheetContainer">
			<view class="liItem jc-between">
				<view style="backgroundImage: url(/static/mine/likeSheet.png)" class="musicCover" />
				<view class="rightInfo">
					<view class="title">听歌排行</view>
					<view class="dsc">累计听歌{{userInfo.listenSongs}}首</view>
				</view>
			</view>
			<view class="liItem jc-between">
				<view style="backgroundImage: url(/static/mine/listeningRanking.png)" class="musicCover" />
				<view class="rightInfo">
					<view class="title">我喜欢的音乐</view>
					<view class="dsc">{{this.likeListObj.trackCount}}首，播放{{this.likeListObj.playCount}}次</view>
				</view>
			</view>
		</div>
	
		<div class="sheetContainer">
			<view class="liTitle">
				<view>
					创建的歌单
					<text>
						({{createdList.length}}个)
					</text>
				</view>
			</view>
			<view class="liItem jc-between" v-for="(item,index) in createdList" :key="index">
				<view class="musicCover" :style="{backgroundImage: 'url('+item.coverImgUrl+')'}" />
				<view class="rightInfo">
					<view class="title">{{item.name}}</view>
					<view class="dsc">{{item.trackCount}}首，播放{{item.playCount}}次</view>
				</view>
			</view>
		</div>
	
		<div class="sheetContainer">
			<view class="liTitle jc-between">
				<view>
					收藏的歌单<text>
						({{collectedList.length}})
					</text>
				</view>
	
				<view class="moreList">
					更多歌单
				</view>
			</view>
			<view class="liItem jc-between" v-for="(item,index) in collectedList" :key="index">
				<view class="musicCover" :style="{backgroundImage: 'url('+item.coverImgUrl+')'}" />
				<view class="rightInfo">
					<view class="title">{{item.name}}</view>
					<view class="dsc">{{item.trackCount}}首，播放{{item.playCount}}次</view>
				</view>
			</view>
		</div>
	
		<view class="basicInfo">
			<view class="liTitle">
				<view>
					基本信息
					<text>
						(信息展示可在隐私设置修改)
					</text>
				</view>
			</view>
			<view class="infoLine">
				村龄：{{userInfo.profile.createTime|registerYear}}（{{userInfo.profile.createTime|registerDate}}注册）
			</view>
			<view class="infoLine">
				年龄：{{userInfo.profile.birthday|age}} {{userInfo.profile.birthday|constellation}}
			</view>
			<view class="infoLine">
				地区：{{userInfo.profile.province}} {{userInfo.profile.city}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserDetail,
		getLoginStatus,
		getLikelist,
		getUserSubcount,
		getUserPlaylist
	} from '../../api/account.js'
	export default {
		data() {
			return {
				userId: null,
				userInfo: {
					profile: {}
				},
				likeListObj: {},
				createdList: [],
				collectedList: [],
			};
		},
		created() {
			getLoginStatus().then(async res => {
				this.userId = res.profile.userId
				const uid = this.userId
				this.userInfo = await getUserDetail({
					uid
				})
				this.likeList = (await getLikelist({
					uid
				})).ids
				let playList = (await getUserPlaylist({
					uid
				})).playlist
				playList.forEach((item, index) => {
					if (!index) {
						this.likeListObj = item
					} else if (item.userId == uid) {
						this.createdList.push(item)
					} else {
						this.collectedList.push(item)
					}
				})
			})
		},
		filters: {
			registerDate(val) {
				if (val) {
					let createDate = new Date(val)
					return `${createDate.getFullYear()}年${createDate.getMonth()+1}月`
				} else {
					return val
				}
			},
			registerYear(val) {
				if (val) {
					let createDate = new Date(val)
					let nowDate = new Date()
					let difY = nowDate.getFullYear() - createDate.getFullYear()
					let difM = nowDate.getMonth() - createDate.getMonth()
					let difD = nowDate.getDate() - createDate.getDate()
					if (difY) {
						return `${difY}年`
					} else if (difM) {
						return `${difM}个月`
					} else {
						return `${difD}天`
					}
				} else {
					return val
				}
		
			}
		},
	}
</script>

<style lang="scss" scoped>
.sheets {
			padding: 0 16px;

			.liTitle {
				display: flex;
				align-items: center;
				margin-bottom: 18px;

				>view:first-child {
					font-weight: bold;
					font-size: 16px;

					>text {
						margin-left: 8px;
						font-weight: normal;
						color: #C0C0C0;
						font-size: 14px;
					}
				}
			}

			.sheetContainer {
				padding-bottom: 30px;

				.moreList {
					font-size: 12px;
					border-radius: 20px;
					padding: 4px 8px;
					border: 1px solid rgba($color: #ccc, $alpha: 0.6);
				}

				.liItem {
					margin-top: 8px;
					>view{
						flex-shrink: 0;
					}
					.musicCover {
						@include bgRepeate('/static/mine/none.png');
						width: 46px;
						height: 46px;
						border-radius: 5px;
					}

					.rightInfo {
						flex: 1;
						display: flex;
						flex-direction: column;
						padding: 4px 10px;
						justify-content: space-between;
						overflow: hidden;
						>view{
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
						.title {
							font-size: 16px;
						}

						.dsc {
							font-size: 12px;
							color: #C0C0C0;
						}
					}
				}
			}

			.basicInfo {
				>view:first-child {
					margin-bottom: 10px;
				}

				.infoLine {
					font-size: 13px;
					color: #a1a1a1;
					margin-bottom: 8px;
				}
			}
		}
</style>
